package top.songxs.yygh.hosp.controller.front;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.songxs.yygh.common.result.R;
import top.songxs.yygh.hosp.service.DepartmentService;
import top.songxs.yygh.hosp.service.HospitalService;
import top.songxs.yygh.hosp.service.ScheduleService;
import top.songxs.yygh.model.hosp.Hospital;
import top.songxs.yygh.model.hosp.Schedule;
import top.songxs.yygh.vo.hosp.DepartmentVo;
import top.songxs.yygh.vo.hosp.HospitalQueryVo;
import top.songxs.yygh.vo.hosp.ScheduleOrderVo;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    HospitalService hospitalService;

    @Autowired
    ScheduleService scheduleService;

    @GetMapping("{pageNum}/{pageSize}")
    public R index(@PathVariable Integer pageNum,
                   @PathVariable Integer pageSize,
                   HospitalQueryVo vo) {
        Page<Hospital> hospitals = hospitalService.selectPage(pageNum, pageSize, vo);
        return R.ok().data("pages", hospitals);
    }

    @GetMapping("findByHosname/{hosname}")
    public R findByHosName(@PathVariable String hosname) {
        List<Hospital> list = hospitalService.findByHosName(hosname);
        return R.ok().data("list", list);
    }

    @Autowired
    DepartmentService departmentService;

    @ApiOperation(value = "获取科室列表")
    @GetMapping("department/{hoscode}")
    public R index(@PathVariable String hoscode) {
        List<DepartmentVo> list = departmentService.getDepartmentList(hoscode);
        return R.ok().data("list", list);
    }

    @ApiOperation(value = "医院预约挂号详情")
    @GetMapping("{hoscode}")
    public R item(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        return R.ok().data(map);
    }


    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    //根据医院编号科室编号 workdate获取排班列表
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(@PathVariable String hoscode,
                              @PathVariable String depcode,
                              @PathVariable String workDate) {
        List<Schedule> schedules = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList", schedules);
    }

    @ApiOperation(value = "获取排班详情")
    @GetMapping("getSchedule/{id}")
    public R getScheduleById(@PathVariable String id) {
        Schedule schedule = scheduleService.getScheduleById(id);
        return R.ok().data("schedule", schedule);
    }

    //给远程Feign调用使用的接口
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {

        return scheduleService.getScheduleOrderVo(scheduleId);
    }

}
